<?php //strip
/**
 * Class that implements newsletter model.
 * 
 * @package odNewsletterWpPlugin
 * @subpackage odNewsletterWpPlugin_Models
 * @author Ondrej Donek <ondrejd@gmail.com>
 */
class odNewsletterWpPlugin_Models_Newsletter 
    extends odWpPlugin_Model_Simple
{
  /**
   * Constructor for newsletter model.
   * 
   * @global odCatalogWpPlugin $od_catalog_wpplugin
   * @global wpdb $wpdb
   * @return void
   */
  public function __construct()
  {
    global $od_catalog_wpplugin;
    
    if(defined('IS_UNITTESTING') && IS_UNITTESTING) {
      $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    } else {
      global $wpdb;
    }
    
    parent::__construct(array(
      'tableName' => $wpdb->prefix . 'newsletter',
      'primaryColumn' => 'ID',
      'checkColumn' => 'title',
      'columns' => array(
        'ID' => array('type' => 'bigint', 'length' => 20, 'primary' => true),
        'subject' => array('type' => 'varchar', 'length' => 255, 'notnull' => true, 'default' => ''),
        'text_body' => array('type' => 'text', 'notnull' => true),
        'html_body' => array('type' => 'text', 'notnull' => true),
        'recipients' => array('type' => 'text', 'notnull' => true),
        'created' => array('type' => 'timestamp', 'notnull' => true, 'default' => 'CURRENT_TIMESTAMP'),
        'sent' => array('type' => 'tinyint', 'length' => 1, 'notnull' => true, 'default' => 0),
        'sent_when' => array('type' => 'timestamp', 'notnull' => true)
      )
    ));
  }
} // End of odNewsletterWpPlugin_Models_Newsletter
